<!-- 课程列表 -->
<template>
	<view class="content">
		<view class="contents">
			<swiper class="swiper" circular autoplay v-if="courseData.bannerList && courseData.bannerList.length>0">
				<swiper-item class="swiper_item" v-for="(cell,idx) in courseData.bannerList" :key="idx"
					@click="judegfn(cell)">
					<image :src="cell.imgUrl" mode="aspectFill"></image>
				</swiper-item>
			</swiper>
			<view class="couseBox">
				<!-- 讲师介绍 -->
				<view class="teacher">
<!-- 					<view class="verial" @click="showTeacher=!showTeacher">
						<view class="">讲师介绍</view>
					</view> -->
					<view class="user" v-show="showTeacher" @click='goSeriesList(courseData.lecturerId)'>
						<!-- <avatar :src="courseData.imgUrl" class="avatar"></avatar> -->
						<avatar class="avatar" :src="courseData.imgUrl"></avatar>
						<!-- <image :src="courseData.imgUrl" mode="aspectFill" class="avatar"></image> -->
						<view class="right">
							<view class="fristBox">
								<view>{{courseData.realName}}</view>
								<view class="right1" v-if='courseData.lecturerLable'>{{courseData.lecturerLable}}</view>
							</view>
							<view class="secondBox">{{courseData.introduction}}</view>
						</view>
					</view>
				</view>
				<!-- 课程列表 -->
				<view class="courseList">
					<view class="verial">课程列表</view>
					<block v-if='list.length'>
						<view class="item" v-for='(item,index) in list' :key='index' @click='courseItem(item.id)'>
							<view class="title_img">
								<image :src="item.coverImg" mode="aspectFill" class="img_mode1"></image>
								<view class="right">
									<view class="title">{{item.resourceName}}</view>
									<view class="teacherBox">
										<view class="study-status" v-if="item.pace&&item.pace<100">
											<image
												src="https://yzxk.oss-cn-hangzhou.aliyuncs.com/images/interest/studying.png"
												mode=""></image>
											<text>上次看到{{item.pace}}%</text>
										</view>
										<view class="study-status study-status_completed" v-if="item.pace===100">
											<image
												src="https://yzxk.oss-cn-hangzhou.aliyuncs.com/images/interest/studyed.png"
												mode=""></image>
											<text>已学</text>
										</view>
									</view>
									<view class="right-img">
										<view class="icon">
											<image src="https://yzxk.oss-cn-hangzhou.aliyuncs.com/images/eyes.png"
												mode='aspectFill'></image>
											<view>{{item.watchNum}}</view>
										</view>
										<view class="icon">
											<image src="https://yzxk.oss-cn-hangzhou.aliyuncs.com/images/good.png"
												mode='aspectFill'></image>
											<view>{{item.greatNum}}</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</block>
					<view class="item" v-else>暂无数据</view>
				</view>
			</view>
		</view>

		<!-- 购买系列课程底部按钮 v-if="showMoney"-->
		<view class="bottom_btn">
			<view class="left">
				<view class="total">{{'该系列共'+list.length+'个课程'}}</view>
				<view class="price">
					<view class="original">
						<text>原价：</text>
						<view class="box">
							<text>￥</text>
							<view>{{courseData.courseTotalPrice}}</view>
						</view>
					</view>
					<view class="members">
						<text>会员价：</text>
						<view class="box">
							<text>￥</text>
							<view>{{courseData.coursePrice}}</view>
						</view>
					</view>
				</view>
			</view>

			<view class="right" v-if="courseData.isFree==2">
				<view class="">该系列课程免费</view>
			</view>
			<view class="right" @click='buySeries' v-else-if="courseData.isBuy==0">
				<view class="">购买该系列全部课程</view>
			</view>
			<view v-else class="right">
				<view class="">该系列课程已购买</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		resourceList,
		seriesDetail,
	} from '@/apis/apis.js'
	import Header from '@/components/c_header.vue'
	import avatar from '@/components/avatar.vue';
	export default {
		components: {
			avatar,
			Header,

		},
		data() {
			return {
				courseResourceIds: null,
				seriesId: null,
				courseData: {},
				list: [],
				showTeacher: false,
				isios: false,
				showMoney: false,
			}
		},
		onLoad(options) {
			this.seriesId = options.seriesId ? options.seriesId : "";
			this.courseResourceIds = options.courseResourceIds ? options.courseResourceIds : '';
			let that = this
			uni.getSystemInfo({
				success: function(res) {
					if (res.platform == 'ios') {
						that.isios = true
					}
				}
			})
		},
		onShow() {
			this.init()
		},
		methods: {
			judegfn(v) {
				console.log(v)
				if (!v.linkType) {
					return
				}
				if (v.linkType == 0) return
				if (v.linkType == 1) {
					uni.navigateTo({
						url: `../banner/banner?id=${v.id}`
					});
				}
				if (v.linkType == 2) {
					uni.navigateTo({
						url: v.linkUrl
					});
				}
				if (v.linkType == 3) {
					const url = encodeURIComponent('http://' + v.linkUrl);
					uni.navigateTo({
						url: `/pages/outsideLink/outsideLink?url=${url}`
					});
				}
			},
			async init() {
				const res = await seriesDetail(this.seriesId)
				console.log('系列详情', res)
				// let stingarr = res.data.courseForeachimg.indexOf('[')
				//   if(stingarr != -1){
				// 	res.data.courseForeachimg = JSON.parse(res.data.courseForeachimg)
				//   }
				//   let isaary = res.data.courseForeachimg instanceof Array
				//   if(!isaary){
				// 	let arrr = res.data.courseForeachimg.split(',')
				// 	res.data.courseForeachimg = arrr
				//   }
				//   let emptyArr = []
				//   if(res.data.courseForeachimg.length > 0){
				// 	res.data.courseForeachimg.map(item => {
				// 	  if(!item.url){
				// 		let obj ={
				// 		  url:item,
				// 		  linkType:'',
				// 		  linkUrl:'',
				// 		  content:''
				// 		}
				// 		emptyArr.push(obj)
				// 	  }else{
				// 		emptyArr.push(item)
				// 	  }
				// 	})
				// 	res.data.banner = emptyArr
				// }
				// res.data.banner = res.data.courseForeachimg.split(',')
				this.courseData = res.data
				if (this.courseData.flag && this.isios) {
					this.showMoney = false
				} else {
					this.showMoney = true
				}
				this.showTeacher = this.courseData.isBuy == 0
				const list = await resourceList({
					// pageNum: 1,
					// pageSize: 10,
					courseId: this.courseData.id,
					courseResourceIds: this.courseResourceIds,
					type: 1, // 获取位置（0：首页，1：系列课程）
				})

				this.list = list.data
				console.log('课程列表', this.list)
			},
			//购买系列
			buySeries() {
				uni.navigateTo({
					//区别单独购买还是系列购买（本页面为系列购买）
					url: `../settlement/settlement?type=${1}&courseId=${this.courseData.id}`
				})
			},
			//点击讲师介绍跳回系列列表
			goSeriesList(v) {
				//传讲师id
				uni.navigateTo({
					url: '../seriesList/seriesList?lecturerId=' + v + '&seriesId=' + this.seriesId
				})
			},
			//跳转课程详情页
			courseItem(id) {
				// 传课程id
				uni.navigateTo({
					url: '../courseItem/courseItem?id=' + id
				})
			},
		},

	}
</script>

<style scoped lang="scss">
	.verial {
		font-size: 32rpx;
		font-family: Source Han Sans CN;
		font-weight: bold;
		color: #303030;
		margin: 36rpx 0 28rpx 0;
		padding-left: 24rpx;
		position: relative;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.right-flex {
			display: flex;
			align-items: center;
		}

		.row-img {
			width: 16rpx;
			margin-left: 10rpx;
		}

		.row-t {
			transform: rotate(-90deg);
		}

		.row-b {
			transform: rotate(90deg);
		}
	}

	.verial::before {
		content: '';
		position: absolute;
		width: 10rpx;
		height: 26rpx;
		background: #194FC9;
		border-radius: 4rpx;
		transform: translateY(-50%);
		top: 50%;
		left: 0;
	}

	.bottom_btn {
		width: 720rpx;
		height: 110rpx;
		border-radius: 30rpx;
		box-shadow: 0 0 15rpx 0 rgba(80, 80, 80, 0.0600);
		position: fixed;
		left: 15rpx;
		right: 0;
		bottom: 41rpx;
		z-index: 999;
		display: flex;


		.left {
			width: 70%;
			height: 100%;
			background: #fff;
			border-radius: 40rpx 0 0 0;
			box-sizing: border-box;
			/* #ifdef APP-PLUS */
			padding: 14rpx 0 28rpx 36rpx;
			/* #endif */
			/* #ifdef H5 || MP-WEIXIN */
			padding: 14rpx 0 calc(env(safe-area-inset-bottom) + 28rpx) 36rpx;

			/* #endif */
			.total {
				font-size: 22rpx;
				font-family: Source Han Sans CN;
				color: #8E8E8E;
				line-height: 40rpx;
			}

			.price {
				display: flex;
				align-items: center;

				.original,
				.members {
					display: flex;
					justify-content: space-between;
					align-items: baseline;
					font-family: PingFang SC;
					font-weight: bold;
					color: #194FC9;
				}

				.original {

					font-size: 28rpx;
					margin-right: 34rpx;

					&>text {
						font-size: 26rpx;
						font-family: Source Han Sans CN;
						color: #282828;
					}

					.box {
						display: flex;
						align-items: baseline;

					}
				}

				.members {

					font-size: 32rpx;

					&>text {
						font-size: 26rpx;
						font-size: 26rpx;
						font-family: Source Han Sans CN;
						color: #282828;
					}

					.box {
						display: flex;
						align-items: baseline;
					}
				}
			}
		}

		.right {
			background: #194FC9;
			width: 314.7rpx;
			height: 75rpx;
			border-radius: 30rpx;
			flex-direction: column;
			align-items: center;
			display: flex;
			padding-top: 35rpx;
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #fff;

		}
	}

	.content {
		width: 100%;

		.contents {
			padding-bottom: calc(env(safe-area-inset-bottom) + 30rpx);
			overflow: hidden;
			overflow-y: visible;
			background: #F8F8F8;

			.swiper {
				width: 100%;
				height: 750rpx;

				.swiper_item {
					width: 100%;
					height: 100%;

					&>image {
						width: 100%;
						height: 100%;
					}
				}
			}

			.couseBox {
				width: 92%;
				margin: 0 auto;

				// padding: 0 4%;
				.teacher {
					width: 100%;

					.user {
						margin-top: 35rpx;
						background: #fff;
						font-size: 14px;
						font-family: PingFang SC;
						font-weight: 500;
						color: #939393;
						line-height: 22px;
						padding: 30rpx 54rpx 28rpx 26rpx;
						display: flex;
						box-shadow: 0px 3px 13px 0px rgba(127, 129, 133, 0.1000);
						border-radius: 20rpx;

						.avatar {
							width: 140rpx;
							height: 140rpx;
							border-radius: 10rpx;
							// background-color: rebeccapurple;
						}

						.right {
							// width: 100%;
							padding-left: 32rpx;
							display: flex;
							flex-direction: column;
							justify-content: space-between;

							.fristBox {
								display: flex;
								align-items: center;
								font-size: 30rpx;
								font-family: Source Han Sans CN;
								font-weight: 600;
								color: #111111;

								.right1 {
									margin-left: 26rpx;
									width: 112rpx;
									height: 42rpx;
									background: rgba(82, 196, 255, .12);
									border-radius: 10rpx;
									text-align: center;
									line-height: 42rpx;
									font-size: 24rpx;
									color: #52A3FF;
								}

							}

							.secondBox {
								width: 438rpx;
								font-size: 28rpx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #939393;
								line-height: 44rpx;
								text-overflow: -o-ellipsis-lastline;
								overflow: hidden;
								text-overflow: ellipsis;
								display: -webkit-box;
								-webkit-line-clamp: 2;
								-webkit-box-orient: vertical;
							}
						}
					}
				}

				.courseList {
					width: 100%;
					margin-bottom: 144rpx;

					.item {
						padding: 30rpx 30rpx 10rpx 30rpx;
						background: #fff;
						box-shadow: 0 8rpx 26rpx 0 rgba(127, 129, 133, 0.1500);
						border-radius: 20rpx;
						margin-bottom: 24rpx;
						box-sizing: border-box;
						height: 190rpx;

						.title_img {
							display: flex;

							.img_mode1{
								width: 140rpx;
								height: 140rpx;
								border-radius: 10rpx;
							}

							.right {
								// height: 100%;
								padding: 4rpx 8rpx 0 32rpx;
								display: flex;
								flex-direction: column;
								justify-content: space-between;

								.title {
									width: 390rpx;
									height: 88rpx;
									font-size: 30rpx;
									font-family: Source Han Sans CN;
									font-weight: 600;
									color: #111111;
									line-height: 44rpx;
									overflow: hidden;
									-webkit-line-clamp: 2;
									text-overflow: ellipsis;
									display: -webkit-box;
									-webkit-box-orient: vertical;

								}

								.price {
									display: flex;
									align-items: baseline;
									font-family: PingFang SC;
									font-weight: bold;
									color: #194FC9;
									font-size: 36rpx;

									&>text {
										font-size: 22rpx;
									}
								}
								.right-img {
									width: 450rpx;
									display: flex;
									align-items: center;
									justify-content: flex-end;
									font-size: 24rpx;
									font-family: Source Han Sans CN;
									color: #B0B0B0;
									margin-top: 10rpx;
								
									.icon {
										display: flex;
										align-items: center;
										margin: 0 20rpx;
								
										&>image {
											width: 24rpx;
											height: 18rpx;
											margin-right: 8rpx;
										}
									}
								}
							}
						}

						.teacherBox {
							display: flex;
							justify-content: space-between;
							align-items: center;
							padding-top: 20rpx;
							padding-right: 10rpx;

							.left {
								display: flex;
								align-items: center;
								font-size: 26rpx;
								font-family: Source Han Sans CN;
								color: #B2B2B2;

								&>text {
									color: #4A4A4A;
								}
							}

							.study-status {
								font-size: 26rpx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: #4DBB55;
								line-height: 30rpx;

								image {
									width: 24rpx;
									height: 24rpx;
									vertical-align: middle;
									margin-right: 6rpx;
								}
							}

							.study-status_completed {
								color: #194FC9;
							}

							.study-status_nostudy {
								color: #777;
							}
						}


					}
				}
			}
		}
	}
</style>
